local hx__guicai = fk.CreateSkill {
  name = "hx__guicai",
}

hx__guicai:addEffect(fk.AskForRetrial, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(hx__guicai.name) and not player.dead
end,
on_use = function(self, event, target, player, data)
    local room = player.room
    local suits = {"spade", "heart", "club", "diamond"}
    local numbers = {}
    for i = 1, 13 do
        table.insert(numbers, tostring(i))
    end
    local suit = room:askToChoice(player,{
        choices = suits,
        skill_name = hx__guicai.name,
        prompt = "#hx__guicai-suit",
    })
    local number = tonumber(room:askToChoice(player, {
      choices = numbers,
      skill_name = hx__guicai.name,
      prompt = "#hx__guicai-number",}))
    local cardFound = nil
    local card2Found = nil
    for _, id in ipairs(room.draw_pile) do
        local card11 = Fk:getCardById(id)
        if card11:getSuitString() == suit and not cardFound then
            cardFound = id
        end
        if card11.number == number and not card2Found then
            card2Found = id
        end
    end
    if cardFound then
        local thecard = Fk:getCardById(cardFound)
        if thecard then
          player.room:changeJudge{
            card = thecard,
            player = player,
            data = data,
            skillName = hx__guicai.name,
            response = true,
          }
        end
    end
    if card2Found then
      room:sendLog{
        type = "#hx__fankui_change2",
        from = player.id,
      }
      room:obtainCard(player, card2Found, false, fk.ReasonPrey)
    end
end
})


return hx__guicai
